﻿using System;
using System.Web.UI;
using CardLogistics.Web.Components;
using CardLogistics.DAL.Sys;
using CardLogistics.Model.Sys;

namespace CardLogistics.Web
{
    public partial class Login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        override protected void OnInit(EventArgs e)
        {
            this.RequiresAuthentication = false;
            this.EnsureRenderInFrame = false;
        }

        protected void btn_Login_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string loginName = this.txt_Name.Value;
                string passWord = new DESC().Encrypto(this.txt_Pwd.Value);
                Sys_SysUserInfo user = new Sys_SysUserInfoData().GetModel(loginName, passWord);
                if (user != null)
                {
                    if (user.USERSTATUS == 1)//0正常 1禁用
                    {
                        ShowMessageBox("此用户已被禁用！");
                    }
                    else
                    {
                        string url = this.AppPath + @"/main.html";
                        string retUrl = Request.QueryString["returnUrl"];
                        if (retUrl != null && retUrl.Trim().Length > 0)
                        {
                            url = retUrl;
                        }
                        AuthCookie auCookie = new AuthCookie();
                        auCookie.SetLoggedUser(user);
                        InsertLog("登录系统");
                        Response.Redirect("main.html");
                    }
                }
                else
                {
                    ShowMessageBox("用户名或密码错误！");
                }
            }
            else
            {
                this.ShowMessageBox("登录失败：用户名或密码未填写完整！");
            }
        }
    }
}